UMAP
SCpubr::do_DotPlot(protcod_filt,features=list('Microglia'=AB_markers_curated$Microglia),
group.by = "RNA_snn_res.0.1", cluster.idents=F, split.by = 'Organoids') +
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))

SCpubr::do_DotPlot(protcod_filt, features=list('Epithelial'=AB_markers$`Epithelial Cells`,
'Radial Glia'=AB_markers$`Radial Glia`,
'NPCs'=AB_markers$NPCs,
'Neurons'=AB_markers$Neurons,
'Exc. neurons'=AB_markers$`Excitatory neurons`,
'Inh. neurons'=AB_markers$`Inhibitory neurons`,
'Interneurons'=AB_markers$Interneurons,
'Cortical neurons'=AB_markers$`Cortical neurons`,
'Mesenchymal'=AB_markers$`Mesenchymal cells`,
'Oligodendrocytes'=AB_markers$Oligodendrocytes,
'Astrocytes'=AB_markers$Astrocytes,
'Microglia'=AB_markers$Microglia,
'Cilia'=AB_markers$Cilia,
'ChP'=AB_markers$ChP),
group.by = "seurat_clusters", cluster.idents=F)+
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))

Idents(protcod_filt) <- protcod_filt$RNA_snn_res.0.1
identity <- c('0'='NSC',
'1'='NPC',
'2'='Neurons',
'3'='NPC',
'4'='Neurons',
'5'='Mesenchymal/ChP',
'6'='Microglia')
protcod_filt <- RenameIdents(object = protcod_filt, identity)
protcod_filt@meta.data$identity <- as.character(Idents(protcod_filt))
table(protcod_filt$identity)
##
## Mesenchymal/ChP Microglia Neurons NPC NSC
## 1080 141 15909 20406 40301
protcod_filt$identity <- factor(protcod_filt$identity, levels=unique(protcod_filt$identity))
DimPlot(protcod_filt, reduction = 'umap', group.by='identity', cols = RColorBrewer::brewer.pal(7,'Accent')[c(1,2,3,5,6)])

#add condition factor
protcod_filt$Organoids <- NA
protcod_filt@meta.data[protcod_filt$orig.ident %in% c('023','024'),]$Organoids <- 'CO'
protcod_filt@meta.data[!protcod_filt$orig.ident %in% c('023','024'),]$Organoids <- 'COiMg'
DimPlot(protcod_filt, reduction = 'umap', group.by='identity', split.by = 'Organoids', cols = RColorBrewer::brewer.pal(7,'Accent')[c(1,2,3,5,6)])

DimPlot(protcod_filt, reduction = 'umap', group.by='identity', split.by = 'cell.line', cols = RColorBrewer::brewer.pal(7,'Accent')[c(1,2,3,5,6)])

table(protcod_filt$cell.line,protcod_filt$identity)
##
## NSC Neurons NPC Mesenchymal/ChP Microglia
## MSN38 19511 8532 9858 516 16
## WTC11 20790 7377 10548 564 125
prop <- data.frame('CO'=prop.table(table(protcod_filt$identity,protcod_filt$Organoids)[,1]),'COiMg'=prop.table(table(protcod_filt$identity,protcod_filt$Organoids)[,2]))
df <- data.frame('Cell Type'=rep(rownames(prop),2),'Organoids'=c(rep('CO',5),rep('COiMg',5)),'Percentage'=round(c(prop[,1],prop[,2])*100,2))
ggplot(df, aes(x = Organoids, y = Percentage, fill = `Cell.Type`))+
geom_bar(stat = "identity")+
geom_text(aes(label = paste(Percentage,"%")), position = position_stack(vjust = 0.5)) +
scale_fill_manual(values=RColorBrewer::brewer.pal(7,'Accent')[c(1,2,3,5,6)]) +
theme_minimal()

SCpubr::do_DotPlot(protcod_filt, features=list('Microglia'=AB_markers$Microglia,'Cilia'=AB_markers$Cilia,
'ChP'=AB_markers$ChP),
cluster.idents=F, group.by = 'Organoids')+
theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust=1))
